package com.ruoyi.web.controller.api.user;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.system.domain.PEvaluate;
import com.ruoyi.system.domain.bo.PEvaluateBo;
import com.ruoyi.system.service.IPEvaluateService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.Arrays;

/**
 * @Description:
 * @Author: wk
 * @Date: 2022/7/25 8:36
 * @Version: 1.0
 */

@Api(value = "用户评价咨询师控制器", tags = {"前端-用户评价"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/evaluate")
public class EvaluateApiController {
    private final IPEvaluateService iPEvaluateService;
    private final ISysUserService iSysUserService;

    @ApiOperation("用户评价咨询师")
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PEvaluateBo bo) {
        iPEvaluateService.insertFontByBo(bo);
        return R.ok("新增成功！");
    }

//    /**
//     * 查询用户评价咨询师列表
//     */
//    @ApiOperation("查询用户评价咨询师列表")
//    @GetMapping("/list")
//    public TableDataInfo<PEvaluate> list(PEvaluate bo, PageQuery pageQuery) {
//        return iPEvaluateService.queryPageList(bo, pageQuery);
//    }

    @ApiOperation("删除用户评价咨询师")
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        if (ObjectUtil.isNull(ids)) {
            return R.fail();
        }

        iPEvaluateService.deleteWithValidByIds(Arrays.asList(ids), false);

        return R.ok();
    }

    @ApiOperation("评价列表咨询师信息")
    @GetMapping("/userInfo")
    public R<SysUser> userInfo(@RequestParam("adviserId") Long adviserId) {
        return R.ok(this.iSysUserService.selectUserById(adviserId));
    }

    @ApiOperation("评价列表")
    @GetMapping("/evaluateList")
    public TableDataInfo<PEvaluate> evaluateList(@RequestParam("adviserId") Long adviserId, @RequestParam("type") String type, PageQuery pageQuery) {
        return this.iPEvaluateService.evaluateList(adviserId, type, pageQuery);
    }
}
